const webpack = require('webpack')
// 处理vue文件的
const VueLoaderPlugin = require('vue-loader/lib/plugin')

const HtmlWebpackPlugin = require('html-webpack-plugin')

module.exports = {
  // 设置入口文件
  entry: './src/main.js',
  output: {
    filename: 'bundle.js'
  },
  // 模块处理的Loader
  module: {
    rules: [
      {
        test: /\.png|jpe?g|gif$/,
        use: {
          loader: 'url-loader',
          options: {
            esModule: false,
            limit: 6 * 1024,
            name: 'img/[name].[contenthash:8].[ext]'
          }
        }  
      },
      {
        test: /\.vue$/,
        use: 'vue-loader'
      },
      {
        test: /\.css|less|sass$/,
        use: [
          'style-loader',
          'css-loader'
        ]  // 这里执行的顺序是从后往前，所以是先执行css-loader
      }, 
      {
        test: /\.js$/,
        use: 'babel-loader',
        exclude: '/node_modules/'
      }, 
      {
        test: /\.(js|vue)$/,
        use: {
          loader: 'eslint-loader',
          options: {
            formatter: require('eslint-friendly-formatter') // 默认的错误提示方式
          }
        },
        enforce: 'pre', // 编译前检查
        exclude: /node_modules/, // 不检查的文件
        include: ['/src'], // 要检查的目录
      }
    ]
  },
  plugins: [
    new VueLoaderPlugin(),
    new HtmlWebpackPlugin({
      title: 'vue-app-base',
      template: './public/index.html'
    }),
    new webpack.DefinePlugin({
      'BASE_URL': JSON.stringify('')
    })
  ]
}